cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA14.log", replace

clear all
set more off

mat Results = J(33, 9, -9)

use "RawData/GallupDataBJPS.dta", clear

// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Party")
// Drops Obs. w/o Gender
drop if female < 0
// Drops Obs. w/o Weights
drop if final_weight < 0
// Drops Obs. w/o Dem., Ind., or Rep.
keep if party == -1 | party == 0 | party == 1
// Keeps In-Person Surveys
keep if survey == 1

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
sort middle_date
format middle_date %td
gen year = year(middle_date)  

// Codes Dem. as 0, Ind. as 1/2, and Rep. as 1
// Partisan 1 = Leaners Ind, Partisan 2 = Leaners as Partisans
gen partisan = 0 if party == -1
replace partisan = 1 if party == 1
replace partisan = .5 if party == 0

save "ProcessedData/temp.dta", replace

// Age
use "ProcessedData/temp.dta", clear
drop if age < 18 | age >= 100
gen age1839 = (age >= 18 & age <= 39)
gen age4059 = (age >= 40 & age <= 59)
gen age6099 = (age >= 60 & age <= 99)
foreach var of varlist age1839-age6099 {
gen femaleX`var' = female * `var'
}
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan age4059-femaleXage6099 [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 1] = _b[femaleXage1839]
mat Results[`j' + 1, 1] = -_se[femaleXage1839]
cap count if age1839 == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 1] = r(N)
mat Results[`j', 2] = _b[femaleXage4059]
mat Results[`j' + 1, 2] = -_se[femaleXage4059]
cap count if age4059 == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 2] = r(N)
mat Results[`j', 3] = _b[femaleXage6099]
mat Results[`j' + 1, 3] = -_se[femaleXage6099]
cap count if age6099 == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 3] = r(N)
}
}

// Black
use "ProcessedData/temp.dta", clear
drop if black < 0
gen femaleXyes = female * (black == 1)
gen femaleXno = female * (black == 0)
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan black femaleXyes femaleXno [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 4] = _b[femaleXyes]
mat Results[`j' + 1, 4] = -_se[femaleXyes]
cap count if black == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 4] = r(N)
mat Results[`j', 5] = _b[femaleXno]
mat Results[`j' + 1, 5] = -_se[femaleXno]
cap count if black == 0 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 5] = r(N)
}
}

// Education
use "ProcessedData/temp.dta", clear
drop if education < 0
gen nohs = (education == 1)
gen hs = (education == 2 | education == 3)
gen somecol = (education == 4)
gen col = (education == 5)
foreach var of varlist nohs-col {
gen femaleX`var' = female * `var'
}
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan hs-femaleXcol [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 6] = _b[femaleXnohs]
mat Results[`j' + 1, 6] = -_se[femaleXnohs]
cap count if nohs == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 6] = r(N)
mat Results[`j', 7] = _b[femaleXhs]
mat Results[`j' + 1, 7] = -_se[femaleXhs]
cap count if hs == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 7] = r(N)
mat Results[`j', 8] = _b[femaleXsomecol]
mat Results[`j' + 1, 8] = -_se[femaleXsomecol]
cap count if somecol == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 8] = r(N)
mat Results[`j', 9] = _b[femaleXcol]
mat Results[`j' + 1, 9] = -_se[femaleXcol]
cap count if col == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 9] = r(N)
}
}
matlist Results

log close
